<?php

/**
 * 
 *
 * @version $Id: kats.inc.php,v 1.11 2005/01/05 13:36:39 phppc Exp $
 * @copyright 2004 
 **/

// Setzen der Datenbankfelder

$this->uf_field[1] = "name";
	$this->uf_input[1]["ml"] = 255;
	$this->uf_input[1]["size"] = 50;
$this->uf_field[2] = "kat_id";
	$this->uf_input[2]["type"] = "kat";
	$this->uf_input[2]["first_lang"] = "admin_kat_first";
	$this->uf_input[2]["size"] = 4;
$this->uf_field[3] = "image_id";
	$this->uf_input[3]["type"] = "input_db";
	$this->uf_input[3]["optional"] = 1;
	$this->uf_input[3]["abfrage"] = "SELECT id,name FROM ".$this->config["prefix"]."images WHERE type=\"1\"";
$kats = $this->fun_sg2var("kats");
$perms_array = array(); // array with allowed kat actions
if($this->perm_array["kat_new"] == 1) array_push($perms_array,"new"); 
if($this->perm_array["kat_edit_del"] == 1) array_push($perms_array,"edit","do_edit","del");
$kats = $this->uf_form_conf_def($kats,$perms_array,"show"); // Abfrage der GET-Variable $kats
$this->module_new_value["action"] = "kats";

if ($kats == "show") {
    $kat_id = 0;
	$this->kat_rek($kat_id,"admin_kats_show"); // Erstellen der Ausgabe aller Kategorien
	$kats_show_ones = $this->kat_return_value(); // Weitergabe zur Varible
	$this->module_new_value["action"] = "kats"; // Setzen der Hidden-Inputs
	$hidden_array["kats"] = "new";
	// Bei ausreichender Berechtigung wird das Formular zum Erstellen einer Kategorie sichtbar
	$var_array["kat_id"] = 0; // Setzen der Standard-Kategorie. Hier: Keine!
	if ($this->perm_array["kat_new"] == 1) $kats_new_form = $this->uf_create_complete_form("admin_kat_new_title",$hidden_array,"admin_kat_new_submit","form_reset","complete_form","uf/","",$var_array,"admin_kat_","text","icreator_one","uf/");
	$this->tpl_load("kat","admin/");
	$hidden_array["kats"] = "del";
	$hidden_form = $this->uf_create_hidden_form($hidden_array);
	$this->tpl_replace_vars(array("kats_show_ones" => $kats_show_ones,"kats_new_form" => $kats_new_form,"hidden_form" => $hidden_form));
	$nc_main = $this->tpl_output();
	$help_id = 3; // Auswahl der PHPNC-Hilfe
}elseif ($kats == "edit") {
	if ($_GET["kid"] > 0) {
		// Additional input information
		$this->uf_input[2]["dont_show"] = $_GET["kid"];
		$this->uf_input[3]["abfrage"] .= " AND kat_id=\"".$_GET["kid"]."\"";
		$var_array = $this->db_abfrage_az("SELECT * FROM ".$this->config["db_table_kat"]." WHERE id = \"".$_GET["kid"]."\"");
		$this->module_new_value["action"] = "kats";
		$hidden_array["kats"] = "do_edit"; // Setzen der Hidden-Inputs
		$hidden_array["kid"] = $_GET["kid"];
		$nc_main = $this->uf_create_complete_form("admin_kat_edit_title",$hidden_array,"admin_kat_edit_submit","form_reset","complete_form","uf/","admin.php",$var_array,"admin_kat_","text","icreator_one","uf/");
		$help_id = 4;
	}
}elseif ($kats == "del") {
	if (isset($_POST["del_kat"])) {
		$array_del_kats = array();
		foreach ($_POST["del_kat"] as $del_kat_id) {
			if ($this->uf_form_conf_def($del_kat_id,$array_del_kats,"","valid_input") != 1) array_push($array_del_kats,$del_kat_id);
			$this->kat_rek($del_kat_id,"ids");
			$array_del_kats = array_merge($array_del_kats,$this->kat_return_value());
		}
		if (count($array_del_kats) > 0) {
			$sql_del = $this->uf_create_where_part($array_del_kats);
			$sql_del_kat = $this->uf_create_where_part($array_del_kats,"kat");
			if ($this->db_abfrage_q("DELETE FROM ".$this->config["prefix"]."kat WHERE $sql_del")){ // Deletion of chosen kats
				$this->db_abfrage_q("UPDATE ".$this->config["prefix"]."main SET kat=\"0\" WHERE $sql_del_kat"); // Unset kat_id in concerned news
				$this->message_green[] = 3;
			}
		}
	}else $this->message_red[] = 1;
	$this->w_leitung["number"] = 2;
	$this->w_leitung["url"] = $this->fun_make_link("admin.php");
}elseif ($kats == "new") {
	list($input_array,$abfrage1,$abfrage2) = $this->uf_create_array_conf("insert");
	if ($this->uf_form_conf($input_array) == 1) {
		$_POST = $this->uf_secure($_POST);
		$this->db_abfrage_q("INSERT ".$this->config["db_table_kat"]." ($abfrage1) VALUES ($abfrage2)");
		$this->message_green[] = 1;
	}else $this->message_red[] = 1;
	$this->w_leitung["number"] = 2;
	$this->w_leitung["url"] = $this->fun_make_link("admin.php","kats=show");
}elseif ($kats == "do_edit") {
	list($input_array,$abfrage) = $this->uf_create_array_conf("update");
	if ($this->uf_form_conf($input_array) == 1) {
		$_POST = $this->uf_secure($_POST);
		$this->db_abfrage_q ("UPDATE ".$this->config["db_table_kat"]." SET $abfrage WHERE id = \"".$_POST["kid"]."\"");
		$this->message_green[] = 2;
		$this->w_leitung["number"] = 2;
		$this->w_leitung["url"] = $this->fun_make_link("admin.php");
	}else {
		$this->message_red[] = 1;
		$this->w_leitung["number"] = 1;
	}

}

?>
